package nicg.st.util;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;

import com.bingqi.Info.srcUsrInfo;

import nicg.st.Communicate;
import nicg.st.entity.MyConfig;
import nicg.st.exception.GlobalException;
import nicg.st.outerAPI.OuterInfo;
import nicg.st.service.XmlService;

/**
 * 接受文件的工具
 * 
 * @author GeChen
 *
 */
public class RecevieUtil {
	@Resource
	MyConfig myConfig;
	@Autowired
	XmlService xmlService;

	public static final String RECEIVE_STRING = "recevie";
	public static final String MSG_STRING = "接收传输报告完成！";
	public static final String SUCCESS_STRING = "SUCCESS";

	/**
	 * 接受文件后，显示弹窗，并且插入到数据库
	 * 
	 * @param data
	 * @param srcUsrInfo
	 */
	public void receiveFile(String data, srcUsrInfo srcUsrInfo) {
		if (Communicate.communicateCode == Communicate.SERVICE_FAILURE) {
			throw new GlobalException("传输服务开启失败！");
		}
		// 显示弹窗
		OuterInfo.showBox(myConfig.getPopsLocation(), RecevieUtil.RECEIVE_STRING, RecevieUtil.MSG_STRING,
				srcUsrInfo.srcIp);
		// 插入到数据库
		String reString = xmlService.receiveToDB(data);
		if (reString.equals(RecevieUtil.SUCCESS_STRING)) {
			System.out.println("插入数据库成功！");
		} else {
			System.out.println("插入数据库成功！");
		}
	}

}
